﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.ComponentModel;
using System.Text;
using System.Windows.Data;
using myWindowsMediaPlayer.Model;
using System.Windows.Input;

namespace myWindowsMediaPlayer.ViewModel
{
    class masterMovieModelView : viewModelBase
    {
        private databaseMovie db;
        private ObservableCollection<movieViewModel> movies;
        private ICollectionView collectionView;
        private ICommand addInCurrentList;
        private masterReadChoiceViewModel choiceList;

        public masterMovieModelView(masterReadChoiceViewModel choiceList)
        {
            this.db = new databaseMovie();
            movies = new ObservableCollection<movieViewModel>();

            foreach (movieModel movie in db.Movies)
                this.movies.Add(new movieViewModel(movie));
           this.collectionView = CollectionViewSource.GetDefaultView(this.movies);
           this.choiceList = choiceList;
           
        }

        public ICommand AddInCurrentList
        {
            get
            {
                if (this.addInCurrentList == null)
                    addInCurrentList = new relayCommand(() => this.AddInList());
                return addInCurrentList;
            }
        }

        public void AddInList()
        {
            if (choiceList.Medias.Contains(new libraryViewModel(this.collectionView.CurrentItem as movieViewModel)) != true)
                choiceList.Medias.Add(new libraryViewModel(this.collectionView.CurrentItem as movieViewModel));
        }

        public ObservableCollection<movieViewModel> Movies
        {
            get { return this.movies; }
        }

        public movieViewModel SelectedMovie
        {
            get { return this.collectionView.CurrentItem as movieViewModel; }
        }
    }
}
